package com.sbr.seb.servlet;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sbr.seb.entity.server.Mantis;
import com.sbr.seb.util.UrlConnector;



public class MantisServlet extends HttpServlet {




	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		Mantis mantis = new Mantis();
		mantis.setHost("mantis.dsi.damgm.i2");
		mantis.setPort(null);
		mantis.setLogin("brousse");
		mantis.setPassword("brousse");
		UrlConnector connector = new UrlConnector();
		connector.setLogin(mantis.getLogin());
		connector.setPassword(mantis.getPassword());

		// TODO utiliser un DataInputStream ???
		
		BufferedReader in = connector.getReader(mantis.getBugListUrl());

		PrintWriter out = response.getWriter();
		
		String inputLine = null;
		while ((inputLine = in.readLine()) != null) {
			out.println(inputLine);
		}
		
		out.close();
//		ManagerListReader reader = new ManagerListReader();
//
//		List<TomcatApplication> applicationList = reader.read(in);

		in.close();

//		request.setAttribute("applicationList", applicationList);
//		request.getRequestDispatcher("managerList.jsp").forward(request,response);

	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}


}
